﻿#region File Header
/***********************************************************************
 * Copyright © 2013 Beals Software
 * All Rights Reserved
************************************************************************
Author: Donald Beals
Date: February 4th, 2013
Description: TODO: Write a description of this file here.
****************************** Change Log ******************************
02.04.13 - Created initial file. (dbeals)
***********************************************************************/
#endregion

#region Using Statements
using Newtonsoft.Json;
#endregion

namespace GameJolt.Requests
{
	/// <summary>
	/// 
	/// </summary>
	internal static class TrophyRequestFactory
	{
		[JsonObject]
		internal sealed class TrophyResult : IJsonResult<Trophy[]>
		{
			IJsonResponse<Trophy[]> IJsonResult<Trophy[]>.Response
			{
				get
				{
					return Response;
				}
			}

			[JsonProperty("response")]
			public TrophyResponse Response
			{
				get;
				set;
			}
		}

		[JsonObject]
		internal sealed class TrophyResponse : IJsonResponse<Trophy[]>
		{
			Trophy[] IJsonResponse<Trophy[]>.ResultSet
			{
				get
				{
					return Trophies;
				}
			}

			[JsonProperty("success")]
			public string WasSuccessful
			{
				get;
				set;
			}

			[JsonProperty("message")]
			public string Message
			{
				get;
				set;
			}

			[JsonProperty("trophies")]
			public Trophy[] Trophies
			{
				get;
				set;
			}
		}

		public static JsonRequest<Trophy[], TrophyResult> CreateGetRequest(string gameID, string publicKey, string username, string userToken, TrophyFilter filter)
		{
			var request = new JsonRequest<Trophy[], TrophyResult>(gameID, publicKey, Constants.TrophyUrls.GetUrl, RequestParameter.CreateUsername(username), RequestParameter.CreateUserToken(userToken));
			if(filter == TrophyFilter.Achieved)
				request.Parameters.Add("achieved", true);
			else if(filter == TrophyFilter.Unachieved)
				request.Parameters.Add("unachieved", false);
			return request;
		}

		public static JsonRequest<Trophy[], TrophyResult> CreateGetRequest(string gameID, string privateKey, string username, string userToken, string trophyID)
		{
			return new JsonRequest<Trophy[], TrophyResult>(gameID, privateKey, Constants.TrophyUrls.GetUrl, RequestParameter.CreateUsername(username), RequestParameter.CreateUserToken(userToken), RequestParameter.CreateTrophyID(trophyID));
		}

		public static StringRequest CreateAddAchieveRequest(string gameID, string publicKey, string username, string userToken, string trophyID)
		{
			return new StringRequest(gameID, publicKey, Constants.TrophyUrls.AddAchieveUrl, RequestParameter.CreateUsername(username), RequestParameter.CreateUserToken(userToken), RequestParameter.CreateTrophyID(trophyID));
		}
	}
}
